<!DOCTYPE html>
<html lang="zh-CN">
<head>

<#include "bases/global_style.ftl"> 
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">
</head>

<body>
 
	<div class="page-container" id="loading">

				<div class="row-fluid">
					<div class="span12">
						<div class="portlet box green">
							<div class="portlet-title">
								<div class="caption">
									<i class="fa fa-cogs"></i><#if id??>修改返现活动<#else>新增返现活动</#if>
								</div>
	                            <div class="tools">
	                                <a href="javascript:window.location.reload()" class="reload"></a>
	                            </div>
							</div>

							<div class="portlet-body flip-scroll">
  		
						  		<form class="form-horizontal" role="form" id="dataform">
						  		
						  		   <input type="hidden"   name="id" value="<#if returnMoneyModel.id??>${returnMoneyModel.id}</#if>">
						  		
								   <div class="form-group">
								    <label class="col-sm-4 control-label">返现活动名称<span class="fill-must">*</span></label>
								    <div class="col-sm-5">
								        <input type="text" class="form-control"  placeholder="" name="name"  value="<#if returnMoneyModel.name??>${returnMoneyModel.name}</#if>" required>
								    </div>
								  </div>
								 
								 <div class="form-group">
								    <label class="col-sm-4 control-label">金额(元)<span class="fill-must">*</span></label>
								    <div class="col-sm-5">
								        <input type="number" class="form-control" placeholder="" value="<#if returnMoneyModel.amount??>${returnMoneyModel.amount/100}</#if>" required  onchange="$(this).next().val($(this).val()*100)">
								        <input type="hidden"   name="amount" <#if couponModel.amount??>${couponModel.amount}</#if>>
								    </div>
								  </div>
								  
								  <div class="form-group">
								    <label class="col-sm-4 control-label">发放条件<span class="fill-must">*</span></label>
								    <div class="col-sm-8">
								        <label class="radio-inline">
										  <input type="radio" name="conditionType" id="" value="1" <#if returnMoneyModel.conditionType??><#if returnMoneyModel.conditionType==1>checked</#if></#if> required> 注册成功
										</label>
								    </div>
								    <div class="col-sm-offset-4 col-sm-8">
										<label class="radio-inline">
										  <input type="radio" name="conditionType" id="" value="2" <#if returnMoneyModel.conditionType??><#if returnMoneyModel.conditionType==2>checked</#if></#if> required> 首次登录
										</label>
								    </div>
								    <div class="col-sm-offset-4 col-sm-8">
										<label class="radio-inline">
										  <input type="radio" name="conditionType" id="" value="3" <#if returnMoneyModel.conditionType??><#if returnMoneyModel.conditionType==3>checked</#if></#if>  style="margin-top: 10px;" required> 累积
										  <input type="number" class="form-control sheet-searchInput2"  placeholder="" onchange="$(this).next().val($(this).val()*100)" value="<#if returnMoneyModel.conditionMileage??><#if returnMoneyModel.conditionType==3>${returnMoneyModel.conditionMileage/100}</#if></#if>"> 公里
										  <input type="hidden"  placeholder="" name="conditionMileage" value="<#if returnMoneyModel.conditionMileage??>${returnMoneyModel.conditionMileage}</#if>">  
										</label>
								    </div>
								    <div class="col-sm-offset-4 col-sm-8">
										<label class="radio-inline">
										  <input type="radio" name="conditionType" id="" value="4" style="margin-top: 10px;" required <#if returnMoneyModel.conditionType??><#if returnMoneyModel.conditionType==4>checked</#if></#if>> 累积
										  <input type="number" class="form-control sheet-searchInput2"  placeholder="" name="conditionNum" value="<#if returnMoneyModel.conditionNum??><#if returnMoneyModel.conditionType==4>${returnMoneyModel.conditionNum}</#if></#if>"> 次
										</label>
								    </div>
								  </div>
								  
								  <div class="form-group">
								    <label class="col-sm-4 control-label">车型<span class="fill-must">*</span></label>
								    <div class="col-sm-8">
								        <label class="radio-inline">
										  <input type="radio" name="cartypeRadio" id="" value="1" required <#if returnMoneyModel.cartypeRadio??><#if returnMoneyModel.cartypeRadio==1>checked</#if></#if>> 全部车型
										</label>
								    </div>
									    
								    <div class="col-sm-offset-4 col-sm-8">
										  <label class="radio-inline">
											  <input type="radio" name="cartypeRadio" id="" value="2" required <#if returnMoneyModel.cartypeRadio??><#if returnMoneyModel.cartypeRadio==2>checked</#if></#if>> 选择车型
										  </label>
										  
										  <div style="margin-top: 20px"></div>
										  <label class="radio-inline">车型
											  <select id="cartypes" multiple="multiple" name="cartypes" >
											  </select>
										  </label>
						 
								    </div>
									</div>
								  
								  <div class="form-group">
								    <label class="col-sm-4 control-label">地区<span class="fill-must">*</span></label>
								    <div class="col-sm-8">
								        <label class="radio-inline">
										  <input type="radio" name="areaRadio" id="" value="1" required <#if returnMoneyModel.areaRadio??><#if returnMoneyModel.areaRadio==1>checked</#if></#if>> 全地区
										</label>
								    </div>
									    
								    <div class="col-sm-offset-4 col-sm-8">
										  <label class="radio-inline">
											  <input type="radio" name="areaRadio" id="" value="2" required <#if returnMoneyModel.areaRadio??><#if returnMoneyModel.areaRadio==2>checked</#if></#if>> 选择地区
										  </label>
										  
										  <div style="margin-top: 20px"></div>
										  <label class="radio-inline">省份
											  <select id="provinceids" multiple="multiple" name="provinceids" >
											  </select>
										  </label>
								
										   <div style="margin-top: 20px"></div>
										   <label class="radio-inline">地市
											  <select id="cityids" multiple="multiple"  name="cityids">
											 </select>
										  </label>
								    </div>
								   </div>
									  
								  <div class="form-group">
								    <label class="col-sm-4 control-label">生效时间<span class="fill-must">*</span></label>
								    <div class="col-sm-5">
										  <input type="text" class="form-control" placeholder="请选择生效时间" onFocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" name="begintime" required value="<#if returnMoneyModel.begintime??>${returnMoneyModel.begintime}</#if>">
								    </div>
								  </div>
								  
								  <div class="form-group">
								    <label class="col-sm-4 control-label">截止时间<span class="fill-must">*</span></label>
								    <div class="col-sm-5">
										  <input type="text" class="form-control" placeholder="请选择生效时间" onFocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" name="endtime" required value="<#if returnMoneyModel.endtime??>${returnMoneyModel.endtime}</#if>">
								    </div>
								  </div>
								  
								  <div class="form-group">
								    <label class="col-sm-4 control-label">返现说明</label>
								    <div class="col-sm-5">
								       <textarea class="form-control" rows="3" placeholder="" name="comment"><#if returnMoneyModel.comment??>${returnMoneyModel.comment}</#if></textarea>
								    </div>
								  </div>
									  
								  <div class="form-group">
								    <div class="col-sm-offset-4 col-sm-5 sheet-btnBar">
								      <button type="button" class="btn btn-info sheet-btn" onclick="submitFormdata()">保存</button>
								      <button type="button" class="btn btn-default sheet-btn">取消</button>
								    </div>
								  </div>
								  
								  <div class="form-group" style="display: none">
								    <div class="col-sm-offset-4 col-sm-5 error-resgister">
										<span id="errorContent">错误提示错误提示错误提示</span><!-- 错误提示 -->
									</div>
								  </div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			
<script>  
	$(document).ready(function() {
 
	    
	    dataform=$("#dataform").validate();
	 	selectEvent();//下拉框多选
	 	
	    $('#cartypes').val('<#if returnMoneyModel.cartypes??>${returnMoneyModel.cartypes}</#if>'.split(","));
        $('#cartypes').multiselect("refresh");  
	    $('#provinceids').val('<#if returnMoneyModel.provinceids??>${returnMoneyModel.provinceids}</#if>'.split(","));
        $('#provinceids').multiselect("refresh");  
	    $('#cityids').val('<#if returnMoneyModel.cityids??>${returnMoneyModel.cityids}</#if>'.split(","));
        $('#cityids').multiselect("refresh");  
	});

 
	  
	  function selectEvent(){
		  
		    combox("cartypes","CarType",null,null,true);
	  		 $("#cartypes").multiselect({
		  			noneSelectedText: "===请选择===",
		  			checkAllText:"全选",
		  			uncheckAllText:"全不选",
		  		    selectedText: "选中【#】项 ,共【 #】项"
		     });

	  		 
		    combox("provinceids","Province",null,null,true);
		    $("#provinceids").multiselect({
	  			noneSelectedText: "===请选择===",
	  			checkAllText:"全选",
	  			uncheckAllText:"全不选" ,
	  			uncheckAll: function(event, ui){
	  				setCitymultiselect();
	  	        },
	  			selectedText:function(numChecked, numAll, chkItems) {
	  				setCitymultiselect();
	  				return "选中【"+numChecked+"】项 ,共【 "+numAll+"】项";
	  	        }
	  	        
	  		});
		    setCitymultiselect();
	  }
	  
	  
	  function setCitymultiselect(){
			    var provincesids= $("#provinceids").multiselect().multiselect("getChecked").map(function() {
	                return this.value;
	            }).get();
				
				 $("#cityids").multiselect().multiselect("destroy").hide();
				 combox("cityids","City",provincesids,null,true);
		  		 $("#cityids").multiselect({
		  			noneSelectedText: "===请选择===",
		  			checkAllText:"全选",
		  			uncheckAllText:"全不选",
		  		    selectedText: "选中【#】项 ,共【 #】项"
		  		 });
	  }
	  
	  var dataform;
	  function submitFormdata(){
		  
		     var task=getUrlParamVal('task');
		     
		     dataform.form();
    	     if(dataform.valid()){
                var a,url;
                var nowtime = new Date();
                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
                a=strtemp;

                if(task=='add'){
                	url= "${base}/add_return_money/" + a;
                }else if(task=='edit'){
                	url= "${base}/edit_return_money";
                }
                
                $("#loading").showLoading(); 
        		$.ajax({  
	      		      type : "POST",  
	      		      url : url,
	      		      dataType : "json",  
	      		      data:  $("#dataform").serialize(),
	      		      success : function(data) {  
	      		       	    $('#loading').hideLoading();
		      		        if(data.result == true) {
	   
		      			         jAlert("操作成功！","提示", function() {
		      			            parent.window.opener.location.reload();
		                            closeDialog();
		      		             });
	                           
	                        }else if(data.result == false){
	                        	 jAlert("未知错误！");
	                        }
	                        	
	      		      }  
      		    }); 	    	
    	    }
		  
	  }
	  
</script>
</body>